package com.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.beans.Chapter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.beans.Book;
import com.beans.Novel;
import com.mapper.NovelMapper;
import com.service.NovelService;

@Service
@Transactional
public class NovelServiceImpl implements NovelService {
    @Resource
    private NovelMapper novelMapper;

    public List<Novel> getNovelname(String NovelName) {
        return novelMapper.getNovelname(NovelName);
    }

    public List<Novel> getNovelType(String noveltype) {
        return novelMapper.getNovelType(noveltype);
    }

    public int addNovel(Novel Novel) {
        return novelMapper.addNovel(Novel);
    }

    public int deleteNovel(int id) {
        return novelMapper.deleteNovel(id);
    }

    public Novel getNovelByID(int id) {
        return novelMapper.getNovelByID(id);
    }

    public Novel getNovelByName(String novelname) {
        return novelMapper.getNovelByName(novelname);
    }

    public List<Novel> getAllNovel() {
        return novelMapper.getAllNovel();
    }

    public int updateNovel(Novel Novel) {
        return novelMapper.updateNovel(Novel);
    }

    public int addBook(Book Book) {
        return novelMapper.addBook(Book);
    }

    public int deleteBook(String novelname) {
        return novelMapper.deleteBook(novelname);
    }

    public List<Novel> getBook(String userName) {
        return novelMapper.getBook(userName);
    }

    @Override
    public int getBookByUserName(String userName,String novelname) {
        return novelMapper.getBookByUserName(userName,novelname);
    }

    @Override
    public Map<String, Object> queryByPage(Novel novel, Integer page, Integer limit) {
        Map<String, Object> resMap = new HashMap<>(4);
        PageHelper.offsetPage((page - 1) * limit, limit);
        List<Novel> dataList = novelMapper.getAllNovel();
        PageInfo<Novel> pageInfo = new PageInfo<>(dataList);
        resMap.put("code", 0);
        resMap.put("msg", "查询成功");
        resMap.put("data", pageInfo.getList());
        resMap.put("count", pageInfo.getTotal());
        return resMap;
    }
}


